//
//  Date+String.swift
//  Drop
//
//  Created by hushaohua on 2018/8/13.
//  Copyright © 2018年 init. All rights reserved.
//

import Foundation


extension Int {
    //dhms d h:m':s"
    
    static let secondsPerMinute:Int = 60;
    static let secondsPerHour:Int = 3600;
    static let secondsPerDay:Int = 86400;
    
    //精确到分
    func timeString() -> String{
        if self < Int.secondsPerMinute {
            return "1'";
        }else if self < Int.secondsPerHour {
            let seconds = self % 60;
            if (seconds >= 30){
                return "\(self / Int.secondsPerMinute + 1)'";
            }else{
                return "\(self / Int.secondsPerMinute)'";
            }
        }else if self < Int.secondsPerDay{
            let hours = self / Int.secondsPerHour;
            let leftSeconds = self - hours * Int.secondsPerHour;
            return "\(hours):" + leftSeconds.timeString();
        }else{
            let days = self / Int.secondsPerDay;
            let leftSeconds = self - days * Int.secondsPerDay;
            return "\(days)d " + leftSeconds.timeString();
        }
    }
}

